/**
 * 轮播图插件
 * @author Thousand-paper-crane
 * @param {Object} el
 * @param {Object} option
 * @returns undefined
 */
;(function(){
    function Lbt(el,option){
        this.el=document.querySelector(el)
        this.imgObj=this.el.querySelector('img')
        this.liObjs=this.el.querySelectorAll('ul li')
        this.imgNum=1
        this.t=null
        this.option=option
        this.init()
    }
    Lbt.prototype.init=function(){
        this.setIntervalFn()
        this.liOver()
    }
    Lbt.prototype.setIntervalFn=function(){
        this.t=setInterval(()=>{
            this.imgNum++
            if(this.imgNum==7){
                this.imgNum=1
            }
            this.imgObj.src=`./imgs/img${this.imgNum}.jpg`
            this.liSame()
        },this.option.time)
    }
    Lbt.prototype.liSame=function(){
        this.liObjs.forEach(item=>{
            // item.className=''
            item.style.background=this.option.liColor
        })
        // this.liObjs[this.imgNum-1].className='active'
        this.liObjs[this.imgNum-1].style.background='#c30'
    }
    Lbt.prototype.liOver=function(){
        this.liObjs.forEach((item,i)=>{
            item.onmouseover=()=>{
                clearInterval(this.t)
                this.imgObj.src=`./imgs/img${i+1}.jpg`
                this.imgNum=i+1
                this.liSame()
            }
            item.onmouseout=()=>{
                this.setIntervalFn()
            }
        })
    }
    let lbt1=new Lbt('.lbt1',{
        liColor:'red',
        time:2000
    })
    let lbt2=new Lbt('.lbt2',{
        liColor:'green',
        time:3000
    })
    let lbt3=new Lbt('.lbt3',{
        liColor:'blue',
        time:5000
    })
    window.Lbt=Lbt
})()